/*-----------------------------------------------------
 * Class: BrowseScreen
 * Author: Guy Peleg
 * 
 * the main goal of this class is to be the handller of all file chosing actions within 
 * our project , use this class where ever you write a code for file chooser.
 * the main handler you need to call in the action preformed is "ChooseFile" method
 * ------------------------------------------------------
 */


package Controllers.GenericToolsForController;


import java.io.File;
import java.io.IOException;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;

import Boundry.GenericTools.InputPanel;

public class BrowseScreen extends InputPanel   {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String path;
	private File fileChoosen=null;
	private JFileChooser fc;
	private int returnVal;
	public BrowseScreen()
	{
		 fc = new JFileChooser();
		 fc.setFileFilter(new FileNameExtensionFilter("PDF Files", "pdf"));
		 fc.setMultiSelectionEnabled(false);
		 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);	 
	}
	
	public JFileChooser getBrowseScreen()
	{
		return this.fc;
	}

	public void ChooseFile() 
	{
		// TODO Auto-generated method stub
		int returnVal = fc.showOpenDialog(this.mainPanel);
		 if (returnVal == JFileChooser.APPROVE_OPTION) 
		 {
	             fileChoosen = fc.getSelectedFile();
	             path = fileChoosen.getPath();
	     		 System.out.println(fileChoosen.getPath());
		 }
     }
		
	public PDFfile getFileToSend()
	{
	  if(fileChoosen!=null)
	  {
			try {
			return new PDFfile(fileChoosen);
		  } 
		  catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		  }
	  }
	  return null;
	}	
	
	
	public String getPath(){
		return new String(this.path);
	}
	
	public File getFile()
	{
		return this.fileChoosen;
	}
	public void setFile(File fp)
	{
		this.fileChoosen = fp;
		
	}
	
	public void setReturnVal(int retval)
	{
		this.returnVal = retval;
	}
	
	public int getRetVal()
	{
		return this.returnVal;
	}
	
	
}
